package com.bcu.calculus.controller;

import com.bcu.calculus.UseToken;
import com.bcu.calculus.config.GlobalConfig;
import com.bcu.calculus.entity.Flist;
import com.bcu.calculus.entity.Slist;
import com.bcu.calculus.entity.Message;
import com.bcu.calculus.service.SlistService;
import com.bcu.calculus.utils.LoadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Api(tags = "14  第二路由模块")
@RestController
@RequestMapping("/api/Slist")
public class SlistController {

    @Resource
    private SlistService slistService;

    @Resource
    private GlobalConfig globalConfig;

    @ApiOperation(value = "上传管理端图片")
    @PostMapping(value = "/manageImages", headers = "content-type=multipart/form-data")
    public String getmanageImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
        return globalConfig.hostUrl + "bcucalculusFile/image/slist/manageimage/" + LoadUtil.upload(globalConfig.filePath+"image/slist/manageimage/", files, request);

    }

    @ApiOperation(value = "上传h5图片")
    @PostMapping(value = "/hfImages", headers = "content-type=multipart/form-data")
    //@UseToken(level = 0)
    public String gethfImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
        return globalConfig.hostUrl + "bcucalculusFile/image/slist/hfiveimage/" + LoadUtil.upload(globalConfig.filePath+"image/slist/hfiveimage/", files, request);
    }

    @ApiOperation(value = "添加二级路由")
    @PostMapping(value = "/add")
    public Message<?> addslist(Slist slist){
        return slistService.addSlist(slist);
    }

    @ApiOperation(value = "根据主键删除二级路由")
    @DeleteMapping(value = "/del")
    public Message<?> delslist(String slistId){
        return slistService.delSlist(slistId);
    }

    @ApiOperation(value = "获取所有的二级路由")
    @GetMapping(value = "/getAll")
    public Message<List<Slist>> findAll(){
        return slistService.selectAllSlist();
    }

    @ApiOperation(value = "根据主键获取二级路由")
    @GetMapping(value = "/getOne")
    public Message<Slist> findOne(String slistId){
        return slistService.selectOneSlistById(slistId);
    }

    @ApiOperation(value = "更新二级路由")
    @PutMapping(value = "/update")
    public Message<?> updateslist(Slist slist){
        return slistService.updateSlist(slist);
    }

    @ApiOperation(value = "根据一级路由Id获取包含的二级路由")
    @GetMapping(value = "getSlistByFlistId")
    public Message<List<Slist>> getSlistByFlistId(String FlistId){
        return slistService.getSlistByFlistId(FlistId);
    }


    @ApiOperation(value = "根据用户类型返回二级路由")
    @GetMapping(value = "getSlistByUserType")
    public Message<List<Slist>> getSlistByuserType(String userType){
        return slistService.getSlistByuserType(userType);
    }


    @ApiOperation(value = "根据三级路由Id获取所属的二级路由")
    @GetMapping(value = "getSlistByTlistId")
    public Message<Slist> getSlistByTlistId(String tlistId){
        return slistService.getSlistByTlistId(tlistId);
    }


}
